#! /usr/bin/env python3
# encoding: utf-8
"""
@file: config.py
@author: www.xcooo.cn
@Mail: 602006050@qq.com
"""
import logging
from redis import StrictRedis


class Config(object):
    # 项目配置

    # 配置 secret_key
    SECRET_KEY = 'VKaswIoTGAHRf8LuSf+pX1/OgEQJfon7Pt0Zw1GTKydT2YTRLiPP0dIcRu3/r+uO'

    # 配置数据库
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/information"
    # 动态追踪修改设置 ,如未设置只会提示警告
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 指定当前配置为 true ,SQLAlchemy就可以自动执行 db.session.commit()
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # 配置redis
    REDIS_HOST = '127.0.0.1'
    REDIS_PORT = 6379

    # Session保持配置
    SESSION_TYPE = 'redis'
    # 开启session签名
    SESSION_USE_SIGNER = True
    # 指定 session 保存到 redis(存储session)
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    # 设置需要过期
    SESSION_PERMANENT = False
    # 设置过期时间(设置为两天)
    PERMANENT_SESSION_LIFETIME = 86400 * 2

    # 设置log日志等级
    LOG_LEVEL = logging.DEBUG

class DevelopmentConfig(Config):
    """开发环境下的配置"""
    DEBUG = True

class ProductionConfig(Config):
    """生产环境下的配置"""
    DEBUG = False
    LOG_LEVEL = logging.WARNING

class TestingConfig(Config):
    """单元测试环境下的配置"""
    DEBUG = True
    TESTING = True

config = {
    'development':DevelopmentConfig,
    'production':ProductionConfig,
    'testing':TestingConfig
}